<template>
    <div>
        <a href="/houseadd">房号信息录入</a>
        <h3>房号信息显示页面</h3>
        房型名称: <input type="text" v-model="item.name">
        录入时间: <input type="date" v-model="item.date">
        <input type="button" value="查询" @click="show" class="btn btn-info">
        <table class="table">
            <tbody>
                <tr>
                    <th>排序</th>
                    <th>房型名称</th>
                    <th>房号</th>
                    <th>创建时间</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
                <tr v-for="info in data" :key="info.id">
                    <td>{{info.id}}</td>
                    <td>{{info.name}}</td>
                    <td>{{info.number}}</td>
                    <td>{{moment(info.createTime).format("YYYY-MM-DD HH:mm:ss")}}</td>
                    <td>{{info.isDeleted==true?'上架':'下架'}}</td>
                    <td><input type="button" value="下架" @click="upid(info.id)" v-if="info.isDeleted==true">
                        <input type="button" value="下架" @click="upid(info.id)" v-if="info.isDeleted==false" disabled>
                        &emsp;
                       <input type="button" value="更改" @click="find(info.id)">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios'
import moment from 'moment';
import {ref,reactive,onMounted} from 'vue'
import { useRoute,useRouter } from 'vue-router';
const router = useRouter();
const route = useRoute();


const find=(id:any)=>{
    router.push({
        path:'/houseupdate',
        query:{id:id}
    })
}
 
const upid=(id:any)=>{
    let f=confirm('确认下架吗?')
    if(f)
{
    axios.get('https://localhost:7267/api/House/UpdateId',{params:{id:id}}).then(res=>{
        if(res.data>0)
    {
        alert('下架成功!');
        show();
    }
    else
    {
        alert('更改失败!');
        return;
    }
    })
}
    
}
const item:any =reactive({
    name:'',
    date:''
})
const data:any = ref([]);
onMounted(()=>{
   show(); 
})
const show=()=>{
    axios.get('https://localhost:7267/api/House/GetAll',{params:item}).then(res=>{
        data.value=res.data;
    })
}
</script>

<style scoped>

</style>